// src/api/consumption/index.ts
import {adminRequest, userRequest} from "@/utils/request.ts";
import type {
    PageResp,
    PageConsumption,
    AddConsumption, AddConsumptionResp, PersonalConsumptionResp
} from "@/type/consumption.ts";

enum API {
    GET_PAGE_CONSUMPTION_URL = '/admin/consumption/page',   // get
    GET_A_SINGLE_CONSUMPTION = '/admin/consumption/',   // /consumption/:id get
    ADD_A_CONSUMPTION_URL = '/admin/consumption',
}

// 分页获取消费记录
export const getPageConsumptions = (pageData: PageConsumption) => adminRequest.get<any, PageResp>(API.GET_PAGE_CONSUMPTION_URL, {params: pageData})
// 添加（购买）记录
export const adminAddAConsumption = (data: AddConsumption) => adminRequest.post<any, AddConsumptionResp>(API.ADD_A_CONSUMPTION_URL, data)


// 客户端
enum MEMBER_API {
    ADD_A_CONSUMPTION_URL = '/member/consumption',
    GET_CONSUMPTION_BY_ID = '/member/consumption/',
    GET_PAGE_CONSUMPTION_URL = '/member/consumption/page',
}

// 添加（购买）记录
export const addAConsumption = (data: AddConsumption) => userRequest.post<any, AddConsumptionResp>(MEMBER_API.ADD_A_CONSUMPTION_URL, data)

// 根据id查询消费记录
export const getConsumptionById = (memberId: number) => userRequest.get<any, PersonalConsumptionResp>(`${MEMBER_API.GET_CONSUMPTION_BY_ID}${memberId}`)
// 根据会员分页查询消费记录
export const memberGetPageConsumptions = (pageData: PageConsumption) => userRequest.get<any, PageResp>(MEMBER_API.GET_PAGE_CONSUMPTION_URL, {params: pageData})
